package com.example.myblog_springboot.result;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Result<T> {

    @Schema(description = "状态码")
    private Integer code;

    @Schema(description = "信息")
    private String message;

    @Schema(description = "数据")
    private T data;

    public Result(Integer code, String message, T data) {

        this.code = code;

        this.message = message;

        this.data = data;

    }

    public Result(Integer code, String message) {

        this.code = code;

        this.message = message;

    }

    public Result(T data) {

        this.code = 200;

        this.message = "success";

        this.data = data;

    }

    public static <T> Result<T> success(T data) {

        return new Result<>(data);

    }

    public static <T> Result<T> success(String message, T data) {

        return new Result<>(200, message, data);

    }

    public static <T> Result<T> error(Integer code, String message) {

        return new Result<>(code, message);

    }

    public static <T> Result<T> fail(String message) {

        return new Result<>(500, message);

    }



}
